package org.xmdl.silk.wrap;

import org.xmdl.silk.Assignment;
import org.xmdl.silk.ValueItem;
import org.xmdl.silk.Variable;
import org.xmdl.silk.impl.AssignmentImpl;
import org.xmdl.silk.visit.Visitor;

public class AssignmentWrap extends AssignmentImpl implements StatementWrap {

	private final Assignment w;

	public AssignmentWrap(Assignment e) {
		this.w = e;
		value = WrapUtils.valueItem(e.getValue());
		variable = WrapUtils.variable(e.getVariable());
	}

	@Override
	public void setValue(ValueItem value) {
		value = WrapUtils.valueItem(value);
		w.setValue(value);
	}

	@Override
	public void setVariable(Variable newVariable) {
		variable = WrapUtils.variable(newVariable);
		w.setVariable(variable);
	}

	public boolean accept(Visitor visitor) {
		if (visitor.visitEnter(this)) {
			Wrapped variable = (Wrapped) getVariable();
			Wrapped value = (Wrapped) getValue();
			
			variable.accept(visitor);
			value.accept(visitor);
		}
		boolean result = visitor.visitLeave(this);
		return result;
	}

}
